﻿using System;

namespace ETModel
{
    /// <summary>
    /// 普通消息处理基类
    /// </summary>
    /// <typeparam name="Message">消息类型</typeparam>
	public abstract class AMHandler<Message> : IMHandler where Message: class
	{
		protected abstract void Run(Session session, Message message);

		public void Handle(Session session, object msg)
		{
			Message message = msg as Message;
			if (message == null)
			{
				Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof(Message).Name}");
				return;
			}
			if (session.IsDisposed)
			{
				Log.Error($"session disconnect {msg}");
				return;
			}
			this.Run(session, message);
		}
        /// <summary>
        /// 用传递过来的参数的类型 确定由那个函数处理
        /// </summary>
        /// <returns></returns>
		public Type GetMessageType()
		{
			return typeof(Message);
		}
	}
}